package com.platform.service.client;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

/**
 * Created by flying on 16-9-7.
 */
public class PlatformServiceClientLocator {

    /**
     * application context file path
     */
    private final static String applicationContextPath = "spring/virgo-db-service-client/applicationContext.xml";

    /**
     * application context
     */
    private static ApplicationContext applicationContext = null;

    /**
     * init
     */
    static {
        init();
    }

    public static void init() {
        applicationContext = new ClassPathXmlApplicationContext(applicationContextPath);
    }

    /**
     * get moment service interface
     *
     * @return moment service interface
     */
    public static IUserDBServiceContract getUserDBtContractFacade() {
        boolean status = false;
        IUserDBServiceContract userDBServiceContract = null;
        try {
            Object object;
            if ((object = applicationContext.getBean("userDBContractFacade")) != null) {
                userDBServiceContract = (IUserDBServiceContract) object;
                status = true;
            }
        } catch (Exception ex) {
            logger.error("get userDBContractFacade interface met error:{}", ex);
        } finally {
            logger.info("get userDBContractFacade interface status:{}", status);
        }
        return userDBServiceContract;
    }

    /**
     * get user service interface
     *
     * @return user service interface
     */
    public static IMomentDBServiceContract getMomentDBContractFacade() {
        boolean status = false;
        IMomentDBServiceContract momentDBServiceContract = null;
        try {
            Object object;
            if ((object = applicationContext.getBean("momentDBContractFacade")) != null) {
                momentDBServiceContract = (IMomentDBServiceContract) object;
                status = true;
            }
        } catch (Exception ex) {
            logger.error("get momentDBContractFacade interface met error:{}", ex);
        } finally {
            logger.info("get momentDBContractFacade interface status:{}", status);
        }
        return momentDBServiceContract;
    }

    /**
     * get user service interface
     *
     * @return user service interface
     */
    public static IPayInfoServiceContract getPayDBContractFacade() {
        boolean status = false;
        IPayInfoServiceContract payInfoServiceContract = null;
        try {
            Object object;
            if ((object = applicationContext.getBean("payDBContractFacade")) != null) {
                payInfoServiceContract = (IPayInfoServiceContract) object;
                status = true;
            }
        } catch (Exception ex) {
            logger.error("get payDBContractFacade interface met error:{}", ex);
        } finally {
            logger.info("get payDBContractFacade interface status:{}", status);
        }
        return payInfoServiceContract;
    }

    /**
     * imContract
     *
     * @return
     */
    public static ICommentDBServiceContract getCommentDBContractFacade() {
        boolean status = false;
        ICommentDBServiceContract commentDBServiceContract = null;
        try {
            Object object;
            if ((object = applicationContext.getBean("commentDBContractFacade")) != null) {
                commentDBServiceContract = (ICommentDBServiceContract) object;
                status = true;
            }
        } catch (Exception ex) {
            logger.error("get commentDBContractFacade interface met error:{}", ex);
        } finally {
            logger.info("get commentDBContractFacade interface status:{}", status);
        }
        return commentDBServiceContract;
    }

    /**
     * commentContract
     *
     * @return
     */
    public static IOrderDBServiceContract getOrderDBContractFacade() {
        boolean status = false;
        IOrderDBServiceContract orderDBServiceContract = null;
        try {
            Object object;
            if ((object = applicationContext.getBean("orderDBContractFacade")) != null) {
                orderDBServiceContract = (IOrderDBServiceContract) object;
                status = true;
            }
        } catch (Exception ex) {
            logger.error("get orderDBContractFacade interface met error:{}", ex);
        } finally {
            logger.info("get orderDBContractFacade interface status:{}", status);
        }
        return orderDBServiceContract;
    }

    /**
     * orderContract
     *
     * @return
     */
    public static IDNSDBServiceContract getDNSDBContractFacade() {
        boolean status = false;
        IDNSDBServiceContract idnsdbServiceContract = null;
        try {
            Object object;
            if ((object = applicationContext.getBean("dnsDBContractFacade")) != null) {
                idnsdbServiceContract = (IDNSDBServiceContract) object;
                status = true;
            }
        } catch (Exception ex) {
            logger.error("get dnsDBContractFacade interface met error:{}", ex);
        } finally {
            logger.info("get dnsDBContractFacade interface status:{}", status);
        }
        return idnsdbServiceContract;
    }

    /**
     * IUserDBLBSServiceContract
     *
     * @return
     */
    public static IUserDBLBSServiceContract getUserLBSServiceContract() {
        boolean status = false;
        IUserDBLBSServiceContract iUserDBLBSServiceContract = null;
        try {
            Object object;
            if ((object = applicationContext.getBean("userDBLBSContractFacade")) != null) {
                iUserDBLBSServiceContract = (IUserDBLBSServiceContract) object;
                status = true;
            }
        } catch (Exception ex) {
            logger.error("get iUserDBLBSServicefacade interface met error:{}", ex);
        } finally {
        }
        return iUserDBLBSServiceContract;
    }

    /**
     * IUserDBDeviceServiceContract
     *
     * @return
     */
    public static IUserDBDeviceServiceContract getUserDBDeviceServiceContract() {
        boolean status = false;
        IUserDBDeviceServiceContract userDBDeviceServiceContract = null;
        try {
            Object object;
            if ((object = applicationContext.getBean("userDBDeviceContractFacade")) != null) {
                userDBDeviceServiceContract = (IUserDBDeviceServiceContract) object;
                status = true;
            }
        } catch (Exception ex) {
            logger.error("get userDBDeviceContractFacade interface met error:{}", ex);
        } finally {
        }
        return userDBDeviceServiceContract;
    }
    
    /**
     * IUserDBDeviceServiceContract
     *
     * @return
     */
    public static IHuoYingDBServiceContract getHuoYingDBServiceContract() {
    	IHuoYingDBServiceContract huoYingDBServiceContract = null;
    	try {
    		Object object;
    		if ((object = applicationContext.getBean("huoYingDBContractFacade")) != null) {
    			huoYingDBServiceContract = (IHuoYingDBServiceContract) object;
    		}
    	} catch (Exception ex) {
    		logger.error("get huoYingDBContractFacade interface met error:{}", ex);
    	} finally {
    	}
    	return huoYingDBServiceContract;
    }
    
    /**
     * IAppLogDBContract
     *
     * @return
     */
    public static IAppLogDBServiceContract getAppLogDBServiceContract() {
    	IAppLogDBServiceContract appLogDBContract = null;
    	try {
    		Object object;
    		if ((object = applicationContext.getBean("appLogDBContractFacade")) != null) {
    			appLogDBContract = (IAppLogDBServiceContract) object;
    		}
    	} catch (Exception ex) {
    		logger.error("get getAppLogDBServiceContract interface met error:{}", ex);
    	} finally {
    	}
    	return appLogDBContract;
    }
}
